/*
 *@本JS功能：班级管理
 *@本js作者：杨锡君
 *@编写时间：2017年10月31日
 */
$(function() {
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var $tableBox = $(".tableBox");
    var $searchBtn = $(".searchBtn");
    var th = "<tr>" +
        "<th class=\"col-lg-1\">序号</th>" +
        "<th class=\"col-lg-2\">院系</th>" +
        "<th class=\"col-lg-2\">专业</th>" +
        "<th class=\"col-lg-2\">班级</th>" +
        "<th class=\"col-lg-2\">学号</th>" +
        "<th class=\"col-lg-2\">姓名</th>" +
        "<th class=\"col-lg-2\">操作</th>" +
        "</tr>";

    function tabelModel(opt,state) {
        return "<tr data-num=\"0\">" +
            "<td class=\"col-lg-1\">"+ state +"</td>" +
            "<td class=\"col-lg-2\" title=" + opt.departmentName + ">" + opt.departmentName + "</td>" +
            "<td class=\"col-lg-2\" title=" + opt.professionName + ">" + opt.professionName + "</td>" +
            "<td class=\"col-lg-2\" title=" + opt.className + ">" + opt.className + "</td>" +
            "<td class=\"col-lg-2\" title=" + opt.stuorteaId + ">" + opt.stuorteaId + "</td>" +
            "<td class=\"col-lg-2\" title=" + opt.userName + ">" + opt.userName + "</td>" +
            "<td class=\"col-lg-3\">" +
            "<a href=\"javascript:;\" style='margin-right: 0' data-professionname='"+ opt.professionName +"' data-departmentname='"+ opt.departmentName +"' data-classname="+ opt.className +"  data-username="+ opt.userName +"  data-stuorteaid=" + opt.stuorteaId + "  class=\"editBtn\">查看</a>" +
            "</td>" +
            "</tr>";
    }
    var jsonObject = [
        {"courseName":"Python语言程序设计","brokenCount":5,"excellentCount":23,"commonlyCount":11,"knowList":[{"tasklibrary_knowpoint":"Python简介","grade":1},{"tasklibrary_knowpoint":"环境安装","grade":1},{"tasklibrary_knowpoint":"HelloWorld程序","grade":1},{"tasklibrary_knowpoint":"IDLE环境介绍","grade":1},{"tasklibrary_knowpoint":"变量的定义","grade":1},{"tasklibrary_knowpoint":"数据类型","grade":1},{"tasklibrary_knowpoint":"运算符","grade":1},{"tasklibrary_knowpoint":"条件语句","grade":1},{"tasklibrary_knowpoint":"循环","grade":1},{"tasklibrary_knowpoint":"函数的定义与调用","grade":1},{"tasklibrary_knowpoint":"参数列表与返回值","grade":1},{"tasklibrary_knowpoint":"模块","grade":1},{"tasklibrary_knowpoint":"变量的作用域","grade":1},{"tasklibrary_knowpoint":"高级应用","grade":1},{"tasklibrary_knowpoint":"类与对象","grade":1},{"tasklibrary_knowpoint":"继承与多态","grade":1},{"tasklibrary_knowpoint":"高级应用","grade":1},{"tasklibrary_knowpoint":"可变类型与不可变类型","grade":1},{"tasklibrary_knowpoint":"List","grade":1},{"tasklibrary_knowpoint":"Tuple","grade":1},{"tasklibrary_knowpoint":"Set","grade":1},{"tasklibrary_knowpoint":"Dictionary","grade":1},{"tasklibrary_knowpoint":"高级应用","grade":1},{"tasklibrary_knowpoint":"字符串常用操作","grade":2},{"tasklibrary_knowpoint":"格式化方法","grade":2},{"tasklibrary_knowpoint":"正则表达式","grade":2},{"tasklibrary_knowpoint":"os模块的使用","grade":2},{"tasklibrary_knowpoint":"数据的处理","grade":2},{"tasklibrary_knowpoint":"文件读写","grade":2},{"tasklibrary_knowpoint":"异常的定义","grade":2},{"tasklibrary_knowpoint":"异常的分类","grade":2},{"tasklibrary_knowpoint":"异常处理","grade":2},{"tasklibrary_knowpoint":"进程与线程的定义","grade":2},{"tasklibrary_knowpoint":"多线程","grade":2},{"tasklibrary_knowpoint":"多进程","grade":3},{"tasklibrary_knowpoint":"协程","grade":3},{"tasklibrary_knowpoint":"标准库","grade":3},{"tasklibrary_knowpoint":"常用的内置函数","grade":3},{"tasklibrary_knowpoint":"第三方库","grade":3}]},
        {"courseName":"分布式文件系统","brokenCount":5,"excellentCount":32,"commonlyCount":14,"knowList":[{"tasklibrary_knowpoint":"分布式计算的定义","grade":1},{"tasklibrary_knowpoint":"网格计算","grade":1},{"tasklibrary_knowpoint":"分布式计算的原理","grade":1},{"tasklibrary_knowpoint":"分布式计算的难点","grade":1},{"tasklibrary_knowpoint":"常用技术和应用场景","grade":1},{"tasklibrary_knowpoint":"分布式计算的意义","grade":1},{"tasklibrary_knowpoint":"分布式计算与并行计算","grade":1},{"tasklibrary_knowpoint":"分布式计算框架spark","grade":1},{"tasklibrary_knowpoint":"分布式计算框架storm","grade":1},{"tasklibrary_knowpoint":"分布式计算框架对比分析 ","grade":1},{"tasklibrary_knowpoint":"Hadoop体系结构","grade":1},{"tasklibrary_knowpoint":"Hadoop相关子项目 ","grade":1},{"tasklibrary_knowpoint":"Hadoop版本衍化过程","grade":1},{"tasklibrary_knowpoint":"HDFS存储原理","grade":1},{"tasklibrary_knowpoint":"Block切分策略","grade":1},{"tasklibrary_knowpoint":"Block副本放置策略 ","grade":1},{"tasklibrary_knowpoint":"机架感知","grade":1},{"tasklibrary_knowpoint":"访问方式","grade":1},{"tasklibrary_knowpoint":"可靠性策略","grade":1},{"tasklibrary_knowpoint":"HDFS应用","grade":1},{"tasklibrary_knowpoint":"HDFS On Yarn","grade":1},{"tasklibrary_knowpoint":"Hadoop环境配置与搭建","grade":1},{"tasklibrary_knowpoint":"HDFS体系结构","grade":1},{"tasklibrary_knowpoint":"心跳机制","grade":1},{"tasklibrary_knowpoint":"RPC通信机制","grade":1},{"tasklibrary_knowpoint":"HDFS异常处理","grade":1},{"tasklibrary_knowpoint":"HDFS管理与优化","grade":1},{"tasklibrary_knowpoint":"委任与解除","grade":1},{"tasklibrary_knowpoint":"HDFS数据来源","grade":1},{"tasklibrary_knowpoint":"HDFS数据存档","grade":1},{"tasklibrary_knowpoint":"生成数据","grade":1},{"tasklibrary_knowpoint":"mapreduce工作原理","grade":1},{"tasklibrary_knowpoint":"剖析MapReduce编程过程","grade":2},{"tasklibrary_knowpoint":"MapReduce计算模型","grade":2},{"tasklibrary_knowpoint":"作业的调度","grade":2},{"tasklibrary_knowpoint":"MapReduce任务的执行 ","grade":2},{"tasklibrary_knowpoint":"Mapper输入与输出 ","grade":2},{"tasklibrary_knowpoint":"KeyValueInputFormat","grade":2},{"tasklibrary_knowpoint":"多路径输入","grade":2},{"tasklibrary_knowpoint":"输入分片","grade":2},{"tasklibrary_knowpoint":"Mapper输出","grade":2},{"tasklibrary_knowpoint":"Shuffle","grade":2},{"tasklibrary_knowpoint":"MapReduce应用设计模式","grade":2},{"tasklibrary_knowpoint":"Hadoop安全机制","grade":2},{"tasklibrary_knowpoint":"基本数据类型","grade":2},{"tasklibrary_knowpoint":"集合数据类型","grade":2},{"tasklibrary_knowpoint":"文本文件数据编码","grade":3},{"tasklibrary_knowpoint":"数据读取模式","grade":3},{"tasklibrary_knowpoint":"压缩","grade":3}]},
        {"courseName":"数据仓库Hive","brokenCount":3,"excellentCount":18,"commonlyCount":6,"knowList":[{"tasklibrary_knowpoint":"数据定义","grade":1},{"tasklibrary_knowpoint":"数据操作","grade":1},{"tasklibrary_knowpoint":"HiveQL查询","grade":1},{"tasklibrary_knowpoint":"类型转换","grade":1},{"tasklibrary_knowpoint":"桶","grade":1},{"tasklibrary_knowpoint":"视图","grade":1},{"tasklibrary_knowpoint":"索引","grade":1},{"tasklibrary_knowpoint":"按天划分的表","grade":1},{"tasklibrary_knowpoint":"关于分区","grade":1},{"tasklibrary_knowpoint":"唯一键和标准化 ","grade":1},{"tasklibrary_knowpoint":"同一份数据多种处理","grade":1},{"tasklibrary_knowpoint":"对于每个表的分区","grade":1},{"tasklibrary_knowpoint":"分桶表数据存储 ","grade":1},{"tasklibrary_knowpoint":"使用列存储表","grade":1},{"tasklibrary_knowpoint":"使用EXPLAIN","grade":1},{"tasklibrary_knowpoint":"限制调整","grade":1},{"tasklibrary_knowpoint":"JOIN优化","grade":1},{"tasklibrary_knowpoint":"本地模式","grade":1},{"tasklibrary_knowpoint":"并行执行","grade":2},{"tasklibrary_knowpoint":"严格模式","grade":2},{"tasklibrary_knowpoint":"调整mapper和reducer个数","grade":2},{"tasklibrary_knowpoint":"JVM重用 ","grade":2},{"tasklibrary_knowpoint":"索引","grade":2},{"tasklibrary_knowpoint":"动态分区调整","grade":2},{"tasklibrary_knowpoint":"推测执行","grade":3},{"tasklibrary_knowpoint":"单个MapReduce中多个GROUP BY","grade":3},{"tasklibrary_knowpoint":"虚拟列","grade":3}]}
    ];
    function report(opt) {
        var str = "<div class=\"btnBox\">" +
            "<img class=\"fr delReport\" src=\"pc/images/ico_delReport.png\" alt=\"\">" +
            "<img style='display: none;' id="+ opt.stuorteaId +" class=\"fr downReport\" src=\"pc/images/ico_downReport.png\" >" +
            "</div>" +
            "<div id=\"box\">" +
            "<h1>学习报告</h1>" +
            "<hr />" +
            "<div class=\"stuInfoBox\">" +
            "<h3>1、学生信息</h3>" +
            "<div class=\"clear\"></div>" +
            "<div class=\"fl mr\">姓名：&ensp;<span>"+ opt.userName +"</span></div>" +
            "<div class=\"fl mr\">班级：&ensp;<span>"+ opt.className +"</span></div>" +
            "<div class=\"fl mr\">专业：&ensp;<span>"+ opt.professionName +"</span></div>" +
            "<div class=\"fl mr\">学号：&ensp;<span>"+ opt.stuorteaId +"</span></div>" +
            "<div class=\"fl mr\">院系：&ensp;<span>"+ opt.departmentName +"</span></div>" +
            "<div class=\"clear\"></div>" +
            "</div>";
        var str1 = "";

        for(var i = 0;i<jsonObject.length;i++){
            str1 += "<div class=\"stuInfoBox\">" +
                        "<h3>"+ (i+2) +"、"+ jsonObject[i].courseName +"</h3>" +
                        "<h4>1.课程统计</h4>" +
                        "<table id=\"lab1\" cellspacing=\"0\" cellpadding=\"0\">" +
                        "<tr>" +
                        "<th>提交作业数</th>" +
                        "<th>回答问题数</th>" +
                        "<th>提问问题个数\n</th>" +
                        "<th>实验笔记数</th>" +
                        "</tr>" +
                        "<tr>" +
                        "<td>"+ parseInt(Math.random()*100) +"</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"</td>" +
                        "</tr>" +
                        "</table>" +
                        "<table id=\"lab2\" cellspacing=\"0\" cellpadding=\"0\">" +
                        "<tr>" +
                        "<th>实验次数</th>" +
                        "<th>平时成绩</th>" +
                        "<th>考试成绩</th>" +
                        "<th>总成绩</th>" +
                        "</tr>" +
                        "<tr>" +
                        "<td>"+ parseInt(Math.random()*100) +"</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"分</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"分</td>" +
                        "<td>"+ parseInt(Math.random()*100) +"分</td>" +
                        "</tr>" +
                        "</table>" +
                        "<h4 class=\"mt\">2.知识点统计(<span class=\"good\">●</span> 优秀:"+ jsonObject[i].excellentCount+" <span class=\"ok\">▲</span> 良好:"+ jsonObject[i].commonlyCount +" <span class=\"soso\">■</span> 较差:"+ jsonObject[i].brokenCount +" )</h4>" +
                        "<div class=\"clear\"></div>";
                            for(var j = 0;j<jsonObject[i].knowList.length;j++){
                                if(jsonObject[i].knowList[j].grade == 1){
                                    str1 += "<div class=\"fl max mr knowledge\"><span class=\"good\">●</span> "+ jsonObject[i].knowList[j].tasklibrary_knowpoint +"</div>";
                                }
                                if(jsonObject[i].knowList[j].grade == 2){
                                    str1 += "<div class=\"fl max mr knowledge\"><span class=\"ok\">▲</span> "+ jsonObject[i].knowList[j].tasklibrary_knowpoint +"</div>";
                                }
                                if(jsonObject[i].knowList[j].grade == 3){
                                    str1 += "<div class=\"fl max mr knowledge\"><span class=\"soso\">■</span> "+ jsonObject[i].knowList[j].tasklibrary_knowpoint +"</div>";
                                }
                            }
                            str1 += "<div class=\"clear\"></div>";

        }
        var str2 =  "<div class=\"clear\"></div>" +
            "<img class=\"logoImg\" src=\"pc/images/defaultLogo.png\" />" +
            "<div class=\"clear\"></div>" +
            "</div>";



        return str + str1 + str2;
    }
    var classMana = {
        some:'',
        init: function() {
            this.bindEvent();
        },
        bindEvent: function() {
            var self = this;
            var json = {
                "pageNow": 1,
                "pageSize": 10
            };
            if(result.paramData!=undefined){
                if(result.paramData.some!=undefined){
                    json = result.paramData.some;
                    if(json.classId!=undefined){
                        $("#departNames").val(json.classId);
                    }
                    if(json.userName!=undefined){
                        $("#departName").val(json.userName);
                    }
                    if(json.stuorteaId!=undefined){
                        $("#id").val(json.stuorteaId);
                    }
                }
            }
            self.some = json;
            self.tableList(json);
            $searchBtn.off("click").on("click", function() {
                var departmentId = $("#departNames").val();
                var departmentName = $("#departName").val();
                var id = $("#id").val();
                var jsonStr = {
                    "pageNow": 1,
                    "pageSize": 10
                };
                if(departmentId != 0) {
                    jsonStr.classId = Number(departmentId);
                }
                if(departmentName != '') {
                    jsonStr.userName = departmentName;
                }
                if(id != '') {
                    jsonStr.stuorteaId = id;
                }
                self.tableList(jsonStr);
                self.some = jsonStr;
            });


        },
        btnEvent:function(){
            var self = this;
            $(".editBtn").off("click").click(function () {
                var json = JSON.stringify({
                    "pageName":"myStuReports",
                    "paramData":{
                        "stuorteaId":$(this).attr("data-stuorteaid"),
                        "className":$(this).attr("data-classname"),
                        "userName":$(this).attr("data-username"),
                        "departmentName":$(this).attr("data-departmentname"),
                        "professionName":$(this).attr("data-professionname"),
                        "some":self.some
                    }
                });
                window.location.href = "skipPage?jsonStr="+json;
            });
        },
        tableList: function(jsons) {
            var self = this;
            var json = JSON.stringify(jsons);
            loading1.show();
            $.ajax({
                type: "post",
                url: "getAllStuReportByTeaId",
                data: {
                    "jsonStr": json
                },
                async: true,
                success: function(msg) {
                    loading1.hide();
                    msg = JSON.parse(msg);
                    $tableBox.empty();
                    if(msg.stuMap.result == "success"){
                        if(msg.stuMap.stuList.length != 0) {
                            //列表
                            var tabel = "";
                            var state = 0;
                            $.map(msg.stuMap.stuList, function(opt) {
                                state++;
                                tabel += tabelModel(opt,state);
                            });
                            $tableBox.append(th + tabel);
                            self.btnEvent();
                        } else {
                            var trImg = "<tr><td colspan='7'><img style='position:relative;margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></td></tr>";
                            $tableBox.append(th + trImg)
                        }
                        var sumpage = msg.stuMap.totalPage;
                        if(sumpage == 0){
                            sumpage = 1;
                        }
                        var nowpage = 1;
                        var pagenumber = 10;
                        $(".tcdPageCode").createPage({
                            pageCount: sumpage, //总页数
                            current: nowpage, //当前页数
                            pageNumber: pagenumber, //每页显示数量
                            backFn: function(p) {
                                nowpage = p;
                                if(nowpage >= sumpage) {
                                    nowpage = sumpage;
                                }
                                var jsonStr = jsons;
                                jsonStr.pageNow = nowpage;
                                loading1.show();
                                $.ajax({
                                    type: "post",
                                    url: "getAllStuReportByTeaId",
                                    data: {
                                        "jsonStr": JSON.stringify(jsonStr)
                                    },
                                    async: true,
                                    success: function(msg) {
                                        loading1.hide();
                                        msg = JSON.parse(msg);
                                        //获取院系
                                        $("#departNames").html("<option value=\"0\">请选择</option>");
                                        $.map(msg.stuMap.classList, function(opt) {
                                            $("#departNames").append("<option value=" + opt.classId + ">" + opt.className + "</option>");
                                        });
                                        if(msg.stuMap.subObject.classId!=undefined){
                                            $("#departNames").val(msg.stuMap.subObject.classId);
                                        }
                                        if(msg.stuMap.subObject.stuorteaId!=undefined){
                                            $("#id").val(msg.stuMap.subObject.stuorteaId);
                                        }
                                        if(msg.stuMap.subObject.userName!=undefined){
                                            $("#departName").val(msg.stuMap.subObject.userName);
                                        }
                                        //列表
                                        $tableBox.empty();
                                        var tabel = "";
                                        var state = (nowpage-1)*10;
                                        $.map(msg.stuMap.stuList, function(opt) {
                                            state++;
                                            tabel += tabelModel(opt,state);
                                        });
                                        $tableBox.append(th + tabel);
                                        self.btnEvent();
                                    }
                                });
                            }
                        });
                        //获取院系
                        $("#departNames").html("<option value=\"0\">请选择</option>");
                        $.map(msg.stuMap.classList, function(opt) {
                            $("#departNames").append("<option value=" + opt.classId + ">" + opt.className + "</option>");
                        });
                        if(msg.stuMap.subObject.classId!=undefined){
                            $("#departNames").val(msg.stuMap.subObject.classId);
                        }
                        if(msg.stuMap.subObject.stuorteaId!=undefined){
                            $("#id").val(msg.stuMap.subObject.stuorteaId);
                        }
                        if(msg.stuMap.subObject.userName!=undefined){
                            $("#departName").val(msg.stuMap.subObject.userName);
                        }
                    }else{
                        if(msg.stuMap.failMsg == "暂无权限"){
                            parent.location.reload(true);
                        }
                    }

                },
                error:function () {
                    var json = JSON.stringify({
                        "pageName": "error"
                    });
                    window.location.href = "skipPage?jsonStr=" + json;
                }
            });

        }
    };
    classMana.init();
});